/**
 * $Id: MockDirectServlet.java 17 2009-02-17 12:33:06Z azeckoski $
 * $URL: https://entitybus.googlecode.com/svn/trunk/rest/src/test/java/org/sakaiproject/entitybus/rest/jetty/MockDirectServlet.java $
 * TestDirectServlet.java - entity-broker - Jan 2, 2009 4:46:11 PM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Aaron Zeckoski
 * Licensed under the Apache License, Version 2.0
 * 
 * A copy of the Apache License has been included in this 
 * distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
 */

package org.sakaiproject.entitybus.rest.jetty;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * This is a simple version for testing
 * 
 * @author Aaron Zeckoski (azeckoski @ gmail.com)
 */
public class MockExternalServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
    IOException {
        String value = "";
        String path = req.getPathInfo();
        if ("xml".equals(path)) {
            value = "<persons>\n" +
            "  <person>\n" +
            "    <id>azeckoski</id>\n" +
            "    <name>Aaron Zeckoski</name>\n" +
            "    <stuff>AZ_TEST_XML</stuff>\n" +
            "  </person>\n" +
            "</persons>\n";
        } else if ("json".equals(path)) {
            value = "[\n" +
            "    {\n" +
            "        \"id\": \"azeckoski\",\n" +
            "        \"name\": \"Aaron Zeckoski\",\n" +
            "        \"stuff\": \"AZ_TEST_XML\" \n" +
            "    }\n" +
            "]\n";
        } else {
            // default value
            value = "plain test: Aaron Zeckoski; stuff=AZ_TEST_XML; path="+path+" \n";
        }
        resp.getWriter().write(value);
        resp.setStatus(200);
    }

}
